//
//  ViewController.m
//  复选框
//
//  Created by mir_yan on 2018/10/3.
//  Copyright © 2018年 hakeem. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 调用自定义按钮
    [self customBtn];
    
    UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
    // 设置绘制矩阵 frame
    [btn setFrame:CGRectMake(100, 100, 40, 40)];
    
    // 手动设置按钮选中状态
    [btn setSelected:YES];
    
    // 设定Normal Selected状态的样式
    [btn setBackgroundImage:[UIImage imageNamed:@"btn_owner_unselect"] forState:UIControlStateNormal];
    // 选的样式
    [btn setBackgroundImage:[UIImage imageNamed:@"btn_owner_select"] forState:UIControlStateSelected];
    
    
    [btn addTarget:self action:@selector(btnAtion:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示框标题" message:@"提示看信息" preferredStyle:UIAlertControllerStyleAlert];
//    UIAlertControllerStyleActionSheet
    
    UIAlertAction* action1 = [UIAlertAction actionWithTitle:@"按钮标题" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击按钮触发的方法");
    }];
    
    UIAlertAction* action2 = [UIAlertAction actionWithTitle:@"取消按钮" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击按钮触发的方法");
    }];
    
    [alert addAction:action1];
    [alert addAction:action2];
    
    [self presentViewController:alert animated:YES completion:nil];
}

// 设置自定义按钮
- (void)customBtn {
    UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setFrame:CGRectMake(100, 100, 100, 100)];
    
    [btn setTitle:@"普通安妮" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [btn setTitle:@"设置高亮" forState:UIControlStateHighlighted];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    
//    NSString* title = @"按钮标题";
//    NSAttributedString* attrString = [[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:40]}];
//    [btn setAttributedTitle:attrString forState:UIControlStateNormal];
//
    [self.view addSubview:btn];
}

- (void)btnAtion:(UIButton*)sender {
    [sender setSelected:!sender.isSelected];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
